﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Data;

namespace BaseTypesControlLib.Controls
{
    public abstract class ChoiceFieldControl:LabelAndSelectionPanel
    {
        static ChoiceFieldControl()
        {
            FrameworkPropertyMetadata fpm = new FrameworkPropertyMetadata(0,
                FrameworkPropertyMetadataOptions.AffectsMeasure |
                FrameworkPropertyMetadataOptions.AffectsArrange, OnSelectedIndexPropertyChanged);
            SelectedIndexProperty = DependencyProperty.Register("SelectedIndex", typeof(int), 
                typeof(ChoiceFieldControl), fpm);
        }

        public int SelectedIndex
        {
            get { return (int)GetValue(SelectedIndexProperty); }
            set { SetValue(SelectedIndexProperty, value); }
        }
        public static readonly DependencyProperty SelectedIndexProperty;


        private static void OnSelectedIndexPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ChoiceFieldControl ctrl = o as ChoiceFieldControl;
            if (ctrl != null)
                ctrl.UpdateText();
        }

        protected abstract void UpdateText();
    }
}
